package com.itrus.contract.config;

import com.itrus.contract.domain.Contract;
import com.itrus.contract.domain.ContractSigner;
import com.itrus.contract.mapper.ContractMapper;
import com.itrus.contract.mapper.ContractSignerMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * description: 启动完成后，需要初始化执行业务入口 <br>
 * date: 2022/8/24  <br>
 * author: zss <br>
 * version: 1.0.0 <br>
 */
@Slf4j
@Component
public class ContractStartedRunner implements CommandLineRunner {

    @Resource
    private ApplicationContext applicationContext;

    @Resource
    private ContractMapper contractMapper;
    @Resource
    private ContractSignerMapper contractSignerMapper;

    @Override
    public void run(String... args) {

        loadInitData();
        log.info("------所有初始化执行完成！------");
    }


    private void loadInitData(){
        Contract c = new Contract();
        c.setShardingDate(20221220);
        c.setContractName("2022合同001");
        c.setContractStatus(1);
        c.setCreator("u001");
        contractMapper.insert(c);

        ContractSigner signer = new ContractSigner();
        signer.setContractId(c.getId());
        signer.setShardingDate(c.getShardingDate());
        signer.setUserId("u001");
        signer.setEnterpriseId("e001");
        signer.setSignStatus(1);
        contractSignerMapper.insert(signer);
    }

}
